https://leetcode.com/problems/single-number/
找出唯一出現過一次的數字。(面試中偶爾會看到測試你能不能將XOR的特性融入到程式中)
利用XOR的特性,相同數字進行XOR會變為0所以不同的數字進行XOR,最終結果將會變成唯一的那個數字。
int singleNumber(int* nums, int numsSize) {
int count = 0;
for(int i = 0;i<numsSize;i++)
count = count^nums[i];
return count;
}
var singleNumber = function(nums) {
var result = 0;
for(var i = 0; i<nums.length; i++)
{
result = result ^ nums[i];
}
return result;
};
https://github.com/SIAOYUCHEN/leetcode
https://ithelp.ithome.com.tw/users/20100009/ironman/2500
https://ithelp.ithome.com.tw/users/20113393/ironman/2169
https://ithelp.ithome.com.tw/users/20107480/ironman/2435
https://ithelp.ithome.com.tw/users/20107195/ironman/2382
https://ithelp.ithome.com.tw/users/20119871/ironman/2210
https://ithelp.ithome.com.tw/users/20106426/ironman/2136
You must believe in yourself first, and others will believe in you.
你要先相信自己,別人才願意相信你。